// Copyright 2009 Jan Hosang <jan.hosang@gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package tools

import (
    "fmt"
    "strings"
    "container/list"
)

func StrSlicesEqual(a, b []string) bool {
    if len(a) != len(b) {
        return false
    }
    for i, aEl := range a {
        if aEl != b[i] {
            return false
        }
    }
    return true
}

func ListToStrSlice(l *list.List) []string {
    strs := make([]string, l.Len())
    i := 0
    for el := range l.Iter() {
        switch(el.(type)) {
        case string:
            strs[i] = el.(string)
        default:
            strs[i] = el.(fmt.Stringer).String()
        }
        i++
    }
    return strs
}

func ListToString(l *list.List) string {
    return ListToStringf(l, "", ", ", "")
}

func ListToStringf(l *list.List, start, join, end string) string {
    if l == nil {
        return ""
    }
    
    strs := ListToStrSlice(l)
    return start+strings.Join(strs, join)+end
}
